import React, { Component } from 'react'
import './index.css'
export default class index extends Component {
    state = {
        nums: 0
    }
    checkAll = (e) => {
        this.props.checkAll(e.target.checked)
    }
    render() {
        const {todos,handleAllDone,checkAll} = this.props
        let counts = todos.reduce((pre,cur) => {
            if(cur.isComplete) {return pre+1}
               else {return pre}              
        },0)
        let total = todos.length;
        /* 
        defaultChecked 只在第一次渲染的时候生效
        假如需要后面也生效，需要checked配合onChange使用
        */
        return (
            <div className="todo-footer">
                <label>
                    <input type="checkbox" onChange={this.checkAll} checked={counts === total && total!==0}/>
                </label>
                <span>
                    <span>已完成{counts}</span> / 全部{total}
                </span>
                <button className="btn btn-danger" onClick={handleAllDone}>清除已完成任务</button>
            </div>
        )
    }
}
